

// 生成订单二维码
export const createQrCodeApi = async (orderId, miniKey) => {
	uni.$http.responseType = 'arraybuffer'
	const res = await uni.$http.get(`/api/orderInfo/createQrCode/${orderId}/${miniKey}`)
	let url = 'data:image/png;base64,' + uni.arrayBufferToBase64(res.data)
	uni.$http.responseType = ''
	return url
}
//新增修改订单信息
export const addOrderApi = async (type, data) => {
	//0:团购 , 1:普通商品  2:代理商品下单  3:新团购
	let url = '/api/orderInfo/addOrUpdateOrderInfo'
	if (type === '0') {
		url = '/api/orderInfo/placeGroupOrder'
	} else if(type == '2') {
		url = '/api/orderInfo/agentOrder'
	} else if(type == '3') { // 团购商品下单
		url = '/api/orderInfo/groupByOrder'
	} 
	const {
		data: res
	} = await uni.$http.post(url, data)
	return res
}

//预支付 
export const prepaymentApi = async (orderId, payType) => {
	const {
		data: res
	} = await uni.$http.get(`/api/wxPay/pay/${orderId}/${payType}`)
	return res
}

//生成签名
export const addSignApi = async (data) => {
	const {
		data: res
	} = await uni.$http.post('/api/wxPay/addSign', data)
	return res
}

//查询单个订单支付状态
export const getOrderStatusApi = async (orderId) => {
	const {
		data: res
	} = await uni.$http.get(`/api/wxPay/queryPayStatus/${orderId}`)
	return res
}

//查询单个订单详情
export const getOrderDetailApi = async (orderId) => {
	const {
		data: res
	} = await uni.$http.get(`/api/orderInfo/findOrderDetails/${orderId}`)
	return res
}

//订单列表分页查询
export const getOrderListApi = async (data) => {
	const {

		data: res
	} = await uni.$http.post('/api/orderInfo/queryAppListByPage', data)
	return res
}

//取消订单
export const cancelOrderApi = async (orderId) => {
	const {
		data: res
	} = await uni.$http.post(`/api/orderInfo/cancelOrder/${orderId}`)
	return res
}
//删除订单
export const deleteOrderApi = async (orderId) => {
	const {
		data: res
	} = await uni.$http.post(`/api/orderInfo/deleteOrder?orderId=${orderId}`)
	return res
}

//新增订单申请退款
export const addApplyRefundApi = async (data) => {
	const {
		data: res
	} = await uni.$http.post('/api/wxPay/addApplyForRefund', data)
	return res
}

//确认收货
export const confirmOrderApi = async (orderId, isAgent) => {
	let url = '/api/orderInfo/confirmOrder'
	if(isAgent == 0) {
		url = '/api/orderInfo/agentConfirmOrder'
	}
	const {
		data: res
	} = await uni.$http.post(`${url}/${orderId}`)
	return res
}

export const orderTypeApi = async (orderId, payType) => {
	const {
		data: res
	} = await uni.$http.post(`/api/wxPay/pay/${orderId}/${payType}`)
	return res
}

//查询各订单数量
export const getOrderCountApi = async () => {
	const {
		data: res
	} = await uni.$http.get('/api/orderInfo/miniApp/countByStatus')
	return res
}

export const updateStatusApi = async (orderId, status) => {
	const {
		data: res
	} = await uni.$http.post(`/api/orderInfo/updateStatus/${orderId}/${status}`)
	return res
}
